# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
# This source file is part of the Cangjie project, licensed under Apache-2.0
# with Runtime Library Exception.
#
# See https://cangjie-lang.cn/pages/LICENSE for license information.

set(LIB_DIR ${CMAKE_CURRENT_LIST_DIR}/lib)
set(INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include)

set(CANGJIE_ROOT ${LIB_DIR}/cangjie)
set(CANGJIE_SDK_ROOT ${LIB_DIR}/sdks/${TARGET_TYPE})

if (DEFINED ENV{CLION_IDE})
    # Only for CLion IDE parsing
    set(CANGJIE_CJDB_BUILD_TYPE Release CACHE STRING "" FORCE)
    set(CANGJIE_LLVM_BUILD_TYPE Release CACHE STRING "" FORCE)

    set(CANGJIE_BUILD_CJC OFF CACHE BOOL "" FORCE)
    set(CANGJIE_BUILD_STDLIB ON CACHE BOOL "" FORCE)
    set(CANGJIE_BUILD_AST ON CACHE BOOL "" FORCE)
    set(CANGJIE_INCLUDE ${CANGJIE_ROOT}/include CACHE STRING "" FORCE)

    set(CANGJIE_SKIP_FIND_OPENSSL ON CACHE INTERNAL "Do not need openssl")

    add_subdirectory(${CANGJIE_ROOT} EXCLUDE_FROM_ALL)
endif()

add_library(sdk-cangjie-lsp STATIC IMPORTED)

if(WIN32) # WINDOWS
    set(CANGJIE_LSP_PATH "${CANGJIE_SDK_ROOT}/tools/bin/libcangjie-lsp.dll")
elseif(APPLE) # APPLE
    set(CANGJIE_LSP_PATH "${CANGJIE_SDK_ROOT}/tools/lib/libcangjie-lsp.dylib")
else() # LINUX
    set(CANGJIE_LSP_PATH "${CANGJIE_SDK_ROOT}/tools/lib/libcangjie-lsp.so")
endif()
set_target_properties(sdk-cangjie-lsp PROPERTIES IMPORTED_LOCATION ${CANGJIE_LSP_PATH})

add_subdirectory(src)
